INCLUDE(ExternalProject)

if(WIN32)
	set(CLBLAS_CLEW_LIB ${CMAKE_INSTALL_PREFIX}/lib/clew.lib)
else()
	set(CLBLAS_CLEW_LIB ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clew${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

ExternalProject_Add(
    clBLAS-external
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/clMathLibraries/clBLAS/src
    PREFIX ${CMAKE_BINARY_DIR}/clBLAS
    STAMP_DIR ${CMAKE_BINARY_DIR}/clBLAS/stamp
    CMAKE_CACHE_ARGS 
    -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
    -DBUILD_SHARED_LIBS:BOOL=ON
    -DBUILD_CLIENT:BOOL=OFF
    -DBUILD_TEST:BOOL=OFF
    -DOPENCL_INCLUDE_DIRS:STRING=${CMAKE_CURRENT_SOURCE_DIR}/EasyCL/thirdparty/clew/include;${CMAKE_CURRENT_SOURCE_DIR}/EasyCL/thirdparty/clew/include/proxy-opencl
    -DOPENCL_LIBRARIES:STRING=${CLBLAS_CLEW_LIB}
    -DBUILD_KTEST:BOOL=OFF
    -DBUILD_SHOW_WARNINGS:BOOL=OFF
    -DSUFFIX_LIB:STRING=
    -DCORR_TEST_WITH_ACML:BOOL=OFF
    -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
    )

#ExternalProject_Get_Property(clBLAS-external install_dir)
ADD_LIBRARY(clBLAS SHARED IMPORTED)
SET_PROPERTY(TARGET clBLAS PROPERTY IMPORTED_LOCATION "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clBLAS${CMAKE_SHARED_LIBRARY_SUFFIX}")
SET_PROPERTY(TARGET clBLAS PROPERTY IMPORTED_IMPLIB "${CMAKE_INSTALL_PREFIX}/lib/import/clBLAS.lib")
#SET_TARGET_PROPERTIES(clBLAS PROPERTIES IMPORTED_LOCATION ${clBLAS_location})
ADD_DEPENDENCIES(clBLAS clBLAS-external)
SET(CLBLAS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/clMathLibraries/clBLAS/src)
SET(CLBLAS_LIBRARIES ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clBLAS${CMAKE_SHARED_LIBRARY_SUFFIX})
SET(CLBLAS_FOUND ON)

#add_custom_target(clblas_delete_stamp clBLAS-external EasyCL-external
#  ${CMAKE_COMMAND} -E  remove_directory "${CMAKE_BINARY_DIR}/clBLAS/stamp"
#)

#add_dependencies(clBLAS-external EasyCL-external)
#add_dependencies(clBLAS-external EasyCL)
#add_dependencies(clBLAS EasyCL)

